<template>
  <div>
    <a-modal title="批量接单" :visible="visible" @before-open="open" @before-ok="handleOk" @cancel="handleCancel" :align-center="false" title-align="start" width="600px" :mask-closable="false">
      <div>
        <a-form auto-label-width ref="formRef" size="medium" :model="form">
          <a-space direction="vertical" :size="24">
            <a-row>
              <a-col :span="24">
                <a-form-item field="pass" label="是否接单" :rules="rules.pass">
                  <a-radio-group v-model="form.pass">
                    <a-radio :value="true">确认接单</a-radio>
                    <a-radio :value="false">拒绝接单</a-radio>
                  </a-radio-group>
                </a-form-item>
                <a-form-item field="remark" label="拒绝接单原因" :rules="rules.remark" v-if="!form.pass">
                  <a-textarea v-model="form.remark" placeholder="请输入拒绝原因" allow-clear />
                </a-form-item>
              </a-col>
            </a-row>
          </a-space>
        </a-form>
      </div>

      <template #footer>
        <a-button class="gray-outline" @click="handleCancel">取消</a-button>
        <a-button type="primary" :loading="loading" @click="handleOk">确定</a-button>
      </template>
    </a-modal>
  </div>
</template>

<script lang="ts">
  import { defineComponent, ref, reactive, toRefs, computed } from 'vue'
  import { findWarehouseListByParam } from '@/api/warehouse'
  import { updatePackageWarehouse } from '@/api/order'
  import { supplierReceivePurchaseOrder } from '@/api/supplier'
  import { Message } from '@arco-design/web-vue'
  export default defineComponent({
    props: ['ids'],
    setup(props: any, { emit }) {
      let visible = ref(false)
      const formRef = ref()
      const data: any = reactive({
        form: {},
        rules: {
          pass: [{ required: true, message: '请选择是否接单' }],
          remark: [{ required: true, message: '请输入拒绝接单原因' }],
        },
        loading: false,
        houseList: [],
      })

      const open = () => {}
      const handleOk = () => {
        formRef.value.validate(async (valid: any) => {
          if (!valid) {
            data.loading = true
            data.form.ids = props.ids
            const res: any = await supplierReceivePurchaseOrder(data.form)
            if (res.code == 'SUCCESS') {
              Message.success(data.pass ? '接单成功' : '拒绝接单成功')
              handleCancel()
              visible.value = false
              emit('save')
            }
            data.loading = false
          }
        })
      }

      const handleCancel = () => {
        data.form = {}
        formRef.value.resetFields()
        formRef.value.clearValidate()
        data.loading = false
        visible.value = false
      }
      return {
        ...(toRefs(data) as any),
        visible,
        formRef,
        open,
        handleOk,
        handleCancel,
      }
    },
  })
</script>

<style lang="less" scoped></style>
